import requests
import re

url = 'https://www.bilibili.com/'

headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36'}

response = requests.get(url, headers=headers)

# results = re.findall('"response":{.*?}', response.text)
results = re.findall('window.__INITIAL_DATA__=\[.*\]', response.text)
print(len(results), results)

# for _ in results:
#     print(_)

result = results[0].replace('window.__INITIAL_DATA__=', '')
print(type(result), result)


"""
1 ['window.__INITIAL_DATA__=
[
{"request":{"url":"http:\\u002F\\u002Fapi.bilibili.com\\u002Fx\\u002Fweb-show\\u002Fres\\u002Flocs?pf=0&ids=4694",
"config":{"preload":true,"com2co":true,"encWbi":true,"discovery":"main.web-svr.web-show",
"method":"GET","credentials":"include"}},
"response":{"4694":[{"id":1570659,"contract_id":"","res_id":4695,"asg_id":1538809,"pos_num":1,"name":"宇宙不是童话",
"pic":"http:\\u002F\\u002Fi0.hdslb.com\\u002Fbfs\\u002Fbanner\\u002F5b437f40da5d766f0f19c63aa640eb9f0bf88420.jpg",
"litpic":"","url":"https:\\u002F\\u002Fwww.bilibili.com\\u002Fbangumi\\u002Fplay\\u002Fep829439",
"style":0,"agency":"","label":"","intro":"","creative_type":0,"request_id":"1725351078350q172a27a62a226q4313",
"src_id":4695,"area":1,"is_ad_loc":true,"ad_cb":"","title":"","server_type":0,"cm_mark":0,"stime":1725332400,
"mid":"","activity_type":0,"epid":0,"season":null,"room":null,"sub_title":"","ad_desc":"",
"adver_name":"","null_frame":false,"pic_main_color":"#724c4d",
"card_type":0,"business_mark":null,
"inline":{"inline_use_same":1,"inline_type":0,"inline_url":"","inline_barrage_switch":1},"operater":"manager_banner_10948","jump_target":0,"show_urls":null,"click_urls":null},{"id":1570667,"contract_id":"","res_id":4694,"asg_id":1538814,"pos_num":2,"name":"韩立将玄骨逼入绝境","pic":"http:\\u002F\\u002Fi0.hdslb.com\\u002Fbfs\\u002Fbanner\\u002Fc48f212e6535f1f85aa15b7ef426743a3342871f.jpg","litpic":"#2a3043","url":"https:\\u002F\\u002Fwww.bilibili.com\\u002Fbangumi\\u002Fplay\\u002Fep785556","style":0,"agency":"","label":"","intro":"","creative_type":0,"request_id":"1725351078350q172a27a62a226q4313","src_id":4696,"area":1,"is_ad_loc":true,"ad_cb":"","title":"","server_type":0,"cm_mark":0,"stime":1725332400,"mid":"","activity_type":0,"epid":0,"season":null,"room":null,"sub_title":"","ad_desc":"","adver_name":"","null_frame":false,"pic_main_color":"","card_type":0,"business_mark":null,"inline":{"inline_use_same":1,"inline_type":0,"inline_url":"","inline_barrage_switch":1},"operater":"manager_banner_10948","jump_target":0,"show_urls":null,"click_urls":null},{"id":1570642,"contract_id":"","res_id":4694,"asg_id":1538792,"pos_num":3,"name":"来预判UP主的预判吧！参与预测赢好礼\\u003E\\u003E","pic":"http:\\u002F\\u002Fi0.hdslb.com\\u002Fbfs\\u002Fbanner\\u002Fed6be386244c3f1548d9c1feebd477602e68298a.jpg","litpic":"#282536","url":"https:\\u002F\\u002Fwww.bilibili.com\\u002Fblackboard\\u002Fera\\u002FAppleevents2024PC.html","style":0,"agency":"","label":"","intro":"","creative_type":0,"request_id":"1725351078350q172a27a62a226q4313","src_id":4697,"area":1,"is_ad_loc":true,"ad_cb":"","title":"","server_type":0,"cm_mark":0,"stime":1725343200,"mid":"","activity_type":0,"epid":0,"season":null,"room":null,"sub_title":"","ad_desc":"","adver_name":"","null_frame":false,"pic_main_color":"","card_type":0,"business_mark":null,"inline":{"inline_use_same":1,"inline_type":0,"inline_url":"","inline_barrage_switch":1},"operater":"manager_banner_10948","jump_target":0,"show_urls":null,"click_urls":null},{"id":1570219,"contract_id":"","res_id":4694,"asg_id":1538377,"pos_num":4,"name":"豆瓣9.7分！催泪神作登陆B站","pic":"http:\\u002F\\u002Fi0.hdslb.com\\u002Fbfs\\u002Fbanner\\u002F08c9bee2ad824b0d899c3e10096b901132b1905b.png","litpic":"#727566","url":"https:\\u002F\\u002Fwww.bilibili.com\\u002Fbangumi\\u002Fplay\\u002Fep833146","style":0,"agency":"","label":"","intro":"","creative_type":0,"request_id":"1725351078350q172a27a62a226q4313","src_id":4698,"area":1,"is_ad_loc":true,"ad_cb":"","title":"","server_type":0,"cm_mark":0,"stime":1725332400,"mid":"","activity_type":0,"epid":0,"season":null,"room":null,"sub_title":"","ad_desc":"","adver_name":"","null_frame":false,"pic_main_color":"","card_type":0,"business_mark":null,"inline":{"inline_use_same":1,"inline_type":0,"inline_url":"","inline_barrage_switch":1},"operater":"manager_banner_10948","jump_target":0,"show_urls":null,"click_urls":null},{"id":1570600,"contract_id":"","res_id":4694,"asg_id":1538756,"pos_num":5,"name":"成都车展，是开啥玩笑！？老外第一次逛…","pic":"http:\\u002F\\u002Fi0.hdslb.com\\u002Fbfs\\u002Fbanner\\u002F001aa1336a51a5c246cd7176672c0aa2feda3c27.png","litpic":"#724f46","url":"https:\\u002F\\u002Fwww.bilibili.com\\u002Fblackboard\\u002Fera\\u002F2024cdczpc.html","style":0,"agency":"","label":"","intro":"","creative_type":0,"request_id":"1725351078350q172a27a62a226q4313","src_id":4699,"area":1,"is_ad_loc":true,"ad_cb":"","title":"","server_type":0,"cm_mark":0,"stime":1725346800,"mid":"","activity_type":0,"epid":0,"season":null,"room":null,"sub_title":"","ad_desc":"","adver_name":"","null_frame":false,"pic_main_color":"","card_type":0,"business_mark":null,"inline":{"inline_use_same":1,"inline_type":0,"inline_url":"","inline_barrage_switch":1},"operater":"manager_banner_10948","jump_target":0,"show_urls":null,"click_urls":null},{"id":1569904,"contract_id":"","res_id":4694,"asg_id":1538091,"pos_num":6,"name":"KTV必点曲目！特别版《情歌王》惊喜呈现","pic":"http:\\u002F\\u002Fi0.hdslb.com\\u002Fbfs\\u002Fbanner\\u002Fb563baa99d17612d21d76d29f9cfe2740a341e58.png","litpic":"#553524","url":"https:\\u002F\\u002Fwww.bilibili.com\\u002Fbangumi\\u002Fplay\\u002Fep834150","style":0,"agency":"","label":"","intro":"","creative_type":0,"request_id":"1725351078350q172a27a62a226q4313","src_id":4700,"area":1,"is_ad_loc":true,"ad_cb":"","title":"","server_type":0,"cm_mark":0,"stime":1725278400,"mid":"","activity_type":0,"epid":0,"season":null,"room":null,"sub_title":"","ad_desc":"","adver_name":"","null_frame":false,"pic_main_color":"","card_type":0,"business_mark":null,"inline":{"inline_use_same":1,"inline_type":0,"inline_url":"","inline_barrage_switch":1},"operater":"manager_banner_10948","jump_target":0,"show_urls":null,"click_urls":null},{"id":1570637,"contract_id":"","res_id":4694,"asg_id":1538787,"pos_num":7,"name":"壁纸这不就有了！！！","pic":"http:\\u002F\\u002Fi0.hdslb.com\\u002Fbfs\\u002Fbanner\\u002F9021ce77f163c69e226dfdfdf58f8a8d4f4921dc.png","litpic":"#52453c","url":"https:\\u002F\\u002Fwww.bilibili.com\\u002Fblackboard\\u002Fera\\u002FIXO8YeKTJYrvDHUi.html","style":0,"agency":"","label":"","intro":"","creative_type":0,"request_id":"1725351078350q172a27a62a226q4313","src_id":4701,"area":1,"is_ad_loc":true,"ad_cb":"","title":"","server_type":0,"cm_mark":0,"stime":1725292800,"mid":"","activity_type":0,"epid":0,"season":null,"room":null,"sub_title":"","ad_desc":"","adver_name":"","null_frame":false,"pic_main_color":"","card_type":0,"business_mark":null,"inline":{"inline_use_same":1,"inline_type":0,"inline_url":"","inline_barrage_switch":1},"operater":"manager_banner_10948","jump_target":0,"show_urls":null,"click_urls":null},{"id":1570631,"contract_id":"","res_id":4694,"asg_id":1538781,"pos_num":8,"name":"小宇宙奖入围名单公布，见证奇迹诞生！","pic":"http:\\u002F\\u002Fi0.hdslb.com\\u002Fbfs\\u002Fbanner\\u002Fa2e6152126a563ccad48213edb39b4138831e4e7.png","litpic":"#4e2a1b","url":"https:\\u002F\\u002Fwww.bilibili.com\\u002Fblackboard\\u002Factivity-fUeYtuZK69.html","style":0,"agency":"","label":"","intro":"","creative_type":0,"request_id":"1725351078350q172a27a62a226q4313","src_id":4702,"area":1,"is_ad_loc":true,"ad_cb":"","title":"","server_type":0,"cm_mark":0,"stime":1725332400,"mid":"","activity_type":0,"epid":0,"season":null,"room":null,"sub_title":"","ad_desc":"","adver_name":"","null_frame":false,"pic_main_color":"","card_type":0,"business_mark":null,"inline":{"inline_use_same":1,"inline_type":0,"inline_url":"","inline_barrage_switch":1},"operater":"manager_banner_10948","jump_target":0,"show_urls":null,"click_urls":null},{"id":1570359,"contract_id":"","res_id":4694,"asg_id":1538515,"pos_num":9,"name":"狠狠冲榜！！！","pic":"http:\\u002F\\u002Fi0.hdslb.com\\u002Fbfs\\u002Fbanner\\u002Fdfac6b2a2d85861663cfaa15c0458ce414c1d093.png","litpic":"#49494c","url":"https:\\u002F\\u002Fwww.bilibili.com\\u002Fblackboard\\u002Fera\\u002FoCT7snDuyYMEWQBD.html","style":0,"agency":"","label":"","intro":"","creative_type":0,"request_id":"1725351078350q172a27a62a226q4313","src_id":4703,"area":1,"is_ad_loc":true,"ad_cb":"","title":"","server_type":0,"cm_mark":0,"stime":1725292800,"mid":"","activity_type":0,"epid":0,"season":null,"room":null,"sub_title":"","ad_desc":"","adver_name":"","null_frame":false,"pic_main_color":"","card_type":0,"business_mark":null,"inline":{"inline_use_same":1,"inline_type":0,"inline_url":"","inline_barrage_switch":1},"operater":"manager_banner_10948","jump_target":0,"show_urls":null,"click_urls":null},{"id":1570323,"contract_id":"","res_id":4694,"asg_id":1538479,"pos_num":10,"name":"开学好物推荐大赏","pic":"http:\\u002F\\u002Fi0.hdslb.com\\u002Fbfs\\u002Fbanner\\u002Fb8a11f98f83d3ada4b32136ebdc69a52c78a010a.jpg","litpic":"#47372b","url":"https:\\u002F\\u002Fwww.bilibili.com\\u002Fblackboard\\u002Fera\\u002FCOC4OAOYMVuRfNBw.html","style":0,"agency":"","label":"","intro":"","creative_type":0,"request_id":"1725351078350q172a27a62a226q4313","src_id":4704,"area":1,"is_ad_loc":true,"ad_cb":"","title":"","server_type":0,"cm_mark":0,"stime":1725292800,"mid":"","activity_type":0,"epid":0,"season":null,"room":null,"sub_title":"","ad_desc":"","adver_name":"","null_frame":false,"pic_main_color":"","card_type":0,"business_mark":null,"inline":{"inline_use_same":1,"inline_type":0,"inline_url":"","inline_barrage_switch":1},"operater":"manager_banner_10948","jump_target":0,"show_urls":null,"click_urls":null},{"id":1570595,"contract_id":"","res_id":4694,"asg_id":1538751,"pos_num":11,"name":"投稿赢4万奖金和限定周边！","pic":"http:\\u002F\\u002Fi0.hdslb.com\\u002Fbfs\\u002Fbanner\\u002Fa1167a1bfab74274777b22a4fd627f36544bd8c3.png","litpic":"#86603b","url":"https:\\u002F\\u002Fwww.bilibili.com\\u002Fblackboard\\u002Fera\\u002Fig2qWJ2ogNWX3JuJ.html","style":0,"agency":"","label":"","intro":"","creative_type":0,"request_id":"1725351078350q172a27a62a226q4313","src_id":5882,"area":1,"is_ad_loc":true,"ad_cb":"","title":"","server_type":0,"cm_mark":0,"stime":1725292800,"mid":"","activity_type":0,"epid":0,"season":null,"room":null,"sub_title":"","ad_desc":"","adver_name":"","null_frame":false,"pic_main_color":"","card_type":0,"business_mark":null,"inline":{"inline_use_same":1,"inline_type":0,"inline_url":"","inline_barrage_switch":1},"operater":"manager_banner_10948","jump_target":0,"show_urls":null,"click_urls":null}]}}]']

"""